package com.kotlin.heimaplayer.presenter.impl

import com.kotlin.heimaplayer.base.BaseListPresenter
import com.kotlin.heimaplayer.base.BaseView
import com.kotlin.heimaplayer.model.CommonResultBean
import com.kotlin.heimaplayer.model.TencentListBean
import com.kotlin.heimaplayer.model.YueDanItemBean
import com.kotlin.heimaplayer.net.ResponseHandler
import com.kotlin.heimaplayer.net.YueDanRequest
import com.kotlin.heimaplayer.presenter.interf.YueDanPresenter
import com.kotlin.heimaplayer.view.YueDanView

class YueDanPresnterImpl(var yueDanView: BaseView<List<YueDanItemBean>>?):YueDanPresenter,
    ResponseHandler<CommonResultBean<TencentListBean<YueDanItemBean>>> {
    override fun destoryView() {
        if(yueDanView != null){
            yueDanView = null
        }
    }

    override fun onError(type: Int, msg: String?) {
        yueDanView?.onError(msg)
    }

    override fun onSuccess(type: Int, result: CommonResultBean<TencentListBean<YueDanItemBean>>) {
        when(type){
            BaseListPresenter.TYPE_INIT_OR_REFRESH->yueDanView?.loadSuccess(result.data.list)
            BaseListPresenter.TYPE_LOAD_MORE->yueDanView?.loadMore(result.data.list)
        }
    }

    override fun loadDatas() {
        YueDanRequest(BaseListPresenter.TYPE_INIT_OR_REFRESH,1,this).excute()
    }

    override fun loadMore(page: Int) {
        YueDanRequest(BaseListPresenter.TYPE_LOAD_MORE,page,this).excute()
    }
}